package com.jinkaimen.kqb.ui.fragment.h5toapp;

import android.os.Bundle;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.ht.baselibs.core.EventCenter;
import com.ht.baselibs.core.EventCode;
import com.ht.baselibs.ui.base.BaseFragment;
import com.ht.baselibs.utils.ActivityUtils;
import com.ht.baselibs.utils.SharedPreferencesUtils;
import com.jinkaimen.kqb.R;
import com.jinkaimen.kqb.constant.Constants;
import com.jinkaimen.kqb.ui.activity.LoginActivity;
import com.jinkaimen.kqb.ui.activity.addmerchant.WebViewActivity;
import com.jinkaimen.kqb.ui.activity.h5toapp.GoUpgradeActivity;
import com.jinkaimen.kqb.ui.activity.h5toapp.InitiativeScanQrCodeActivity;
import com.jinkaimen.kqb.utils.AppUtils;

import de.greenrobot.event.EventBus;

public class HomeFragment extends BaseFragment {
    private RelativeLayout mRlFragSweepCodeCollection;
    private RelativeLayout mRlFragNoCardsFast;
    private LinearLayout mLvFragUnionpayScanCode;
    private LinearLayout mLlFragMyWallet;
    private LinearLayout mLlFragMyShareBenefit;
    private LinearLayout mLlFragBillSearch;
    private LinearLayout mLlFragMyClientele;
    private LinearLayout mLlFragUpgradeAndDown;
    private LinearLayout mTvFragHomeLeaderContainner;
    private LinearLayout mLlFragMyMerchant;
    private Toast toast;

    @Override
    protected boolean isStaticPage() {
        return true;
    }

    @Override
    protected void initTitleBar() {

    }

    @Override
    protected View initContentView() {
        return LayoutInflater.from(mContext).inflate(R.layout.frag_home_app, null);
    }

    @Override
    protected void initChildView() {
        mRlFragSweepCodeCollection = findViewById(R.id.rl_frag_sweep_code_collection);
        mRlFragNoCardsFast = findViewById(R.id.rl_frag_no_cards_fast);
        mLvFragUnionpayScanCode = findViewById(R.id.lv_frag_unionpay_scan_code);
        mLlFragMyWallet = findViewById(R.id.ll_frag_my_wallet);
        mLlFragMyShareBenefit = findViewById(R.id.ll_frag_my_share_benefit);
        mLlFragBillSearch = findViewById(R.id.ll_frag_bill_search);
        mLlFragMyClientele = findViewById(R.id.ll_frag_my_clientele);
        mLlFragUpgradeAndDown = findViewById(R.id.ll_frag_upgrade_and_down);
        mTvFragHomeLeaderContainner = findViewById(R.id.ll_frag_home_leader_containner);
        mLlFragMyMerchant = findViewById(R.id.ll_frag_my_merchant);
    }

    @Override
    protected void setChildViewListener() {
        mRlFragSweepCodeCollection.setOnClickListener(this);
        mRlFragNoCardsFast.setOnClickListener(this);
        mLvFragUnionpayScanCode.setOnClickListener(this);
        mLlFragMyWallet.setOnClickListener(this);
        mLlFragMyShareBenefit.setOnClickListener(this);
        mLlFragBillSearch.setOnClickListener(this);
        mLlFragMyClientele.setOnClickListener(this);
        mLlFragUpgradeAndDown.setOnClickListener(this);
        mTvFragHomeLeaderContainner.setOnClickListener(this);
        mLlFragMyMerchant.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        Bundle bundle = new Bundle();
        String token = SharedPreferencesUtils.getString(Constants.TOKEN, "");
        isLogIn();
        switch (v.getId()) {
            case R.id.rl_frag_sweep_code_collection://扫码收款
//                bundle.putString(WebViewActivity.TITLE, "扫码收款");
//                bundle.putString(WebViewActivity.URL, "http://hss.qianbaojiajia.com/earn/collection" + Constants.TOKEN_TITLE + token + "&method=" + "scanning");
//                ActivityUtils.startActivity(mContext, WebViewActivity.class, bundle);
                bundle.putInt("type", 1);
                bundle.putString("title", "扫码收款");
                ActivityUtils.startActivity(mContext, InitiativeScanQrCodeActivity.class, bundle);
                break;
            case R.id.rl_frag_no_cards_fast://无卡快捷
                bundle.putString(WebViewActivity.TITLE, "无卡快捷");

                bundle.putString(WebViewActivity.URL, "http://hss.qianbaojiajia.com/earn/collection" + Constants.TOKEN_TITLE + token + "&method=" + "quick");
                ActivityUtils.startActivity(mContext, WebViewActivity.class, bundle);
                break;
            case R.id.lv_frag_unionpay_scan_code://银联扫码
                bundle.putString(WebViewActivity.TITLE, "银联扫码");
                bundle.putString(WebViewActivity.URL, "http://hss.qianbaojiajia.com/earn/collection" + Constants.TOKEN_TITLE + token + "&method=" + "union");
                ActivityUtils.startActivity(mContext, WebViewActivity.class, bundle);
                break;
            case R.id.ll_frag_my_wallet://我的钱包
                bundle.putString(WebViewActivity.TITLE, "我的钱包");
                bundle.putString(WebViewActivity.URL, "http://hss.qianbaojiajia.com/earn/wallet" + Constants.TOKEN_TITLE + token);
                ActivityUtils.startActivity(mContext, WebViewActivity.class, bundle);
                break;
            case R.id.ll_frag_my_share_benefit://我的分润
                bundle.putString(WebViewActivity.TITLE, "我的分润");
                bundle.putString(WebViewActivity.URL, "http://hss.qianbaojiajia.com/earn/profits" + Constants.TOKEN_TITLE + token);
                ActivityUtils.startActivity(mContext, WebViewActivity.class, bundle);
                break;
            case R.id.ll_frag_bill_search://账单查询
                bundle.putString(WebViewActivity.TITLE, "账单查询");
                bundle.putString(WebViewActivity.URL, "http://hss.qianbaojiajia.com/earn/bill" + Constants.TOKEN_TITLE + token);
                ActivityUtils.startActivity(mContext, WebViewActivity.class, bundle);
                break;
            case R.id.ll_frag_my_clientele://我的客户
                bundle.putString(WebViewActivity.TITLE, "我的客户");
                bundle.putString(WebViewActivity.URL, "http://hss.qianbaojiajia.com/earn/client" + Constants.TOKEN_TITLE + token);
                ActivityUtils.startActivity(mContext, WebViewActivity.class, bundle);
                break;
            case R.id.ll_frag_upgrade_and_down://升级降费率
                bundle.putString(WebViewActivity.TITLE, "升级降费率");
                bundle.putString(WebViewActivity.URL, "http://hss.qianbaojiajia.com/earn/upgrade" + Constants.TOKEN_TITLE + token);
                ActivityUtils.startActivity(mContext, WebViewActivity.class, bundle);
                break;
            case R.id.ll_frag_home_leader_containner://商户进件
                toast = Toast.makeText(mContext, "即将开放", Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
                break;
            case R.id.ll_frag_my_merchant://我的商户
                toast = Toast.makeText(mContext, "即将开放", Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
                break;
        }
    }

    @Override
    protected boolean hasEvent() {
        return true;
    }

    @Override
    protected void onEvent(int eventCode, Object data) {
        super.onEvent(eventCode, data);
        switch (eventCode) {
        }
    }

    public void onKeyDown(KeyEvent event) {
        EventBus.getDefault().post(new EventCenter(EventCode.EVENT_CODE_FINISH_ACTIVITY, event));
    }

    private void isLogIn() {
        if (!AppUtils.isLogin()) {
            ActivityUtils.startActivity(mContext, LoginActivity.class);
            return;
        }
    }
}
